<?php

namespace App\Models;

use App\Common\Constant\Params;
use Illuminate\Database\Eloquent\Model;

class OrderEvaluate extends Model
{

    protected $table = 'order_evaluate';

    protected $primaryKey = 'oe_id';

    const CREATED_AT = 'oe_add_time';
    const UPDATED_AT = 'oe_update_time';

    protected $dateFormat = 'U';

    protected $fillable = [
        'oe_orderid',
        'oe_score',
        'oe_quality',
        'oe_attitude',
        'oe_ontime',
        'oe_meid',
        'oe_content',
    ];

    protected $casts = [
        'oe_score' => 'integer',
        'oe_quality' => 'integer',
        'oe_attitude' => 'integer',
        'oe_ontime' => 'integer',
    ];

    protected $touches = ['order'];

    public function order(){
        return $this->belongsTo(Order::class,'oe_orderid');
    }

    public function merchant(){
        return $this->belongsTo(Merchant::class,'oe_meid');
    }

    /**
     * 是否人为评价
     */
    public function getManMadeAttribute()
    {
        return $this->oe_type == Params::ORDER_EVALUATE_MAKE;
    }

    /**
     * 服务评价文字
     */
    public function getScoreTextAttribute()
    {
        return Params::$ORDER_EVALUATE_SCORE[$this->oe_score];
    }

    /**
     * 服务评价小图标
     */
    public function getScoreIcoAttribute()
    {
        return asset(Params::$ORDER_EVALUATE_SCORE_ICO[$this->oe_score]);
    }

}
